

#ifndef _CONFIG_DEFINE_H_
#define _CONFIG_DEFINE_H_

#include <stdint.h>

/*===================================================================*/

typedef enum {
	KEY_T_NONE = 0,
	KEY_T_3DES = 1,
	KEY_T_AES128 = 2,
	KEY_T_3K3DES = 3,
	KEY_T_AES192 = 4,
	KEY_T_AES256 = 5,
	KEY_T_MAX,
}key_type_t;

//密钥标识
//当密钥标识最高位为1，即0x80时，密钥存储在FLASH和SAM中，此时使用FLASH中的密钥，加快速度
//当密钥标识最高位为0，密钥存储在SAM中

#define KID_FLASH_MASK	0x80

typedef enum {
	KID_KFR0	= 0x01,
	KID_KFR		= 0x02,
	KID_KFW		= 0x03,
	KID_KFM		= 0x04,

	KID_KMR		= 0x11,
	KID_KMW		= 0x12,
	KID_KMM		= 0x13,
	
	KID_KCR		= 0x14,
	KID_KCW		= 0x15,
	KID_KCM		= 0x16,	

	KID_KUR		= 0x21,
	KID_KUW		= 0x22,
	KID_KUM		= 0x23,	

	KID_APPLE_PRIV	= 0x31,	//wavelynx apple wallet
	KID_APPLE_CRED	= 0x32, //wavelynx apple wallet

	KID_GOOGLE		= 0x34, //wavelynx google wallet
	
	KID_LEAF		= 0x36, //wavelynx leaf

	KID_SAMSUNG_PAY	= 0x38, ////wavelynx SAMSUNG pay

	//Swiftlane key id	
	KID_SW_AWC_APP = 0x3A,	//Swiftlane Apple Wallet Credential(AWC) 苹果读取USER ID密钥
	KID_SW_SDC_READ = 0x3B,		//Swiftlane Standard DESFire Credential(SDC) 读密钥	
	KID_ACCESS_GRID_APPLE_READ = 0x3C,		//Access Grid Apple Wallet 读密钥	
	KID_ACCESS_GRID_APPLE_PRIVACY = 0x3D,		//Access Grid Apple Wallet 隐私密钥
	// KID_SW_DF_CARD = 0x3C,		//Swiftlane Desfire 卡密钥
	// KID_SW_DF_APP = 0x3D,		//Swiftlane Desfire App密钥
	// KID_SW_APPLE_UID = 0x3E,	//Swiftlane 苹果获取UID密钥
	
}key_id_t;

#pragma pack(push, 1)

typedef struct {	
	uint8_t key_id;		//密钥标识
	uint8_t key_no;		//密钥在卡内的号码
	uint8_t aid[3];		//密钥对应的 AID
}key_set_t;

#define PARAM_VER_APPLE		0x0100
#define PARAM_VER_GOOGLE	0x0100
#define PARAM_VER_LEAF		0x0100
#define PARAM_VER_SWIFTLANE		0x0100
#define PARAM_VER_ACCESS_GRID		0x0100

//苹果钱包读卡参数
typedef struct {
	uint16_t version;		//版本	
	uint8_t epc[7];			//EPC
	key_set_t key_sets[2];	//密钥设置
	uint8_t file_no;		//文件号
	uint16_t offset;		//读取偏移
	uint16_t length;		//读取长度
	uint8_t format;		//格式
}param_apple_wallet_t;

//谷歌钱包读卡参数
typedef struct {
	uint16_t version;		//版本
	key_set_t key_set;
	uint8_t file_no;			//文件号
	uint8_t df_name[16];	//目录名
}param_google_wallet_t;

//LEAF 卡读卡参数
typedef struct {
	uint16_t version;		//版本
	key_set_t key_set;
	uint8_t file_no;			//文件号
}param_leaf_t;

//samsumg pay读卡参数
typedef struct {
	uint16_t version;		//版本
	key_set_t key_set;
	uint8_t file_no;			//文件号	
}param_samsung_pay_t;

typedef struct {
	uint16_t version;
	uint8_t epc[7];
	// key_set_t uid_key_set;	//密钥设置
	key_set_t awc_key_set;
	uint8_t awc_file_no;
	uint16_t awc_length;
	key_set_t sdc_key_set;
	uint8_t div[20];
	uint8_t sdc_file_no;
	uint16_t sdc_length;
}param_swiftlane_t;

typedef struct {
	uint16_t version;
	uint8_t epc[7];
	key_set_t awc_read_key_set;
	key_set_t awc_privacy_key_set;	//密钥设置	
	uint8_t awc_file_no;
	uint16_t awc_length;
}param_access_grid_t;


typedef struct {
	param_apple_wallet_t apple_wallet;	//苹果钱包读卡参数
	param_google_wallet_t google_wallet;	//谷歌钱包读卡参数
	param_leaf_t leaf;	//LEAF 卡读卡参数
	param_samsung_pay_t samsung_pay;	//samsumg pay读卡参数
	param_swiftlane_t swiftlane;	// Swiftlane 读卡参数
	param_access_grid_t access_grid;	// AccessGrid 读卡参数
}config_param_t;

typedef struct {
	param_apple_wallet_t apple_wallet;	//苹果钱包读卡参数
	param_google_wallet_t google_wallet;	//谷歌钱包读卡参数
	param_leaf_t leaf;	//LEAF 卡读卡参数
	param_samsung_pay_t samsung_pay;	//samsumg pay读卡参数	
}config_param_v1_t;
typedef struct {
	uint8_t id;
	uint8_t ver;
	uint8_t type;
	uint8_t data[32];
}key_t;

typedef struct {
	key_t kr;		//读密钥
	// key_t kw;		
	key_t km;		//MAC密钥
}key_group_t;

typedef struct {
	uint32_t magic;
	uint16_t version;
	//工厂密钥
	// key_group_t kgf;
	//制造商密钥
	key_group_t kgm;
	//客户化密钥
	key_group_t kgc;
	//用户密钥
	key_group_t kgu;
}cfg_key_data_t;

typedef struct {
	uint32_t magic;
	uint16_t version;
	key_t apple_keys[2];
	key_t google_key;
	key_t leaf_key;
	key_t samsung_pay_key;
}card_key_data_t;

typedef struct {
	//工厂密钥
	// key_group_t kgf;
	//制造商密钥
	key_group_t kgm;
	//客户化密钥
	key_group_t kgc;
	//用户密钥
	key_group_t kgu;
	key_t apple_keys[2];
	key_t google_key;
	key_t leaf_key;
	key_t samsung_pay_key;
	key_t swiftlane_awc_app;
	key_t swiftlane_sdc_read;
	key_t access_grid_apple_read;
	key_t access_grid_apple_privacy;
}config_key_t;

typedef struct {
	//工厂密钥
	// key_group_t kgf;
	//制造商密钥
	key_group_t kgm;
	//客户化密钥
	key_group_t kgc;
	//用户密钥
	key_group_t kgu;
	key_t apple_keys[2];
	key_t google_key;
	key_t leaf_key;
	key_t samsung_pay_key;	
}config_key_v1_t;

typedef struct {
	uint16_t magic;		//魔数
	uint16_t crc;		//校验和
	uint16_t version;	//版本
	uint16_t length;	//长度
	uint8_t data[];
}config_storage_t;

#pragma pack(pop)

#endif

